package com.zhouchen.shangcheng.adapter;

import java.util.List;

import com.zhouchen.shangcheng.R;
import com.zhouchen.shangcheng.tuliao.ShangPingXinXi;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ShangPingGridViewAdapter extends BaseAdapter{
	private Activity mContext;
	private List<ShangPingXinXi> mList;
	
	public ShangPingGridViewAdapter(Activity context, List<ShangPingXinXi> list){
		mContext = context;
		mList = list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(mList == null)
			return 0;
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		if(mList == null)
			return null;
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		final View itemView;
		if(arg1 == null){
			itemView = (View)mContext.getLayoutInflater().inflate(R.layout.main_gridview_item, null);
		}else{
			itemView = arg1;
		}
		ShangPingXinXi shangpingxinxi = mList.get(arg0);
		ImageView image = (ImageView)itemView.findViewById(R.id.item_image);
		TextView xiangxijieshao = (TextView)itemView.findViewById(R.id.item_text);
		LinearLayout layout = (LinearLayout)itemView.findViewById(R.id.layout_jiage);
		TextView youhuijia = (TextView)layout.findViewById(R.id.youhuijia);
		TextView yuanjia = (TextView)layout.findViewById(R.id.yuanjia);
		
		xiangxijieshao.setText(shangpingxinxi.getmShangPinJieShao());
		youhuijia.setText(shangpingxinxi.getmYouHuiJia());
		yuanjia.setText(shangpingxinxi.getmYuanJia());

		return itemView;
	}
	
}
